﻿using System;
using Token.Piker.Core.Security;
using System.Data;
using Token.Piker.BLL;
using Token.Util;

namespace Token.Piker.Web.AJAX
{
    /// <summary>
    /// GetPhotoInfo 的摘要说明
    /// </summary>
    public class GetPhotoInfo : BaseAjaxHandler
    {
        class PhotoInfo
        {
            public string userName;
            public string position;
            public string uploadTime;
            public string description;
            public string tagName;
            public string src;
        }

        protected override void Mapping()
        {
            OprationMap["getInfo"] = "GetPhotoInfoById";
        }

        protected override void ResponseTemplate(Object data)
        {
            ResponseText = JsonHelper.Serialize(data);
        }

        /// <summary>
        /// 根据图片的ID取得图片信息
        /// 注意本方法仅供首页使用
        /// </summary>
        /// <param name="id">图片ID</param>
        public void GetPhotoInfoById()
        {
            try
            {
                string pid = Context.Request.Params["pid"];
                int id = int.Parse(pid);
                PhotoBLL photoBLL = new PhotoBLL();
                DataSet ds = photoBLL.GetPhotoInfoByID(id);
                DataRow dr = ds.Tables[0].Rows[0];
                PhotoInfo photoInfo = new PhotoInfo();
                photoInfo.userName = dr["UserName"].ToString();
                if (dr["Position"] != null)
                {
                    photoInfo.position = dr["Position"].ToString();
                }
                photoInfo.uploadTime = Convert.ToDateTime(dr["UploadTime"].ToString()).ToLongDateString();
                if (dr["Descrip"] != null)
                {
                    photoInfo.description = dr["Descrip"].ToString();
                }
                photoInfo.tagName = dr["TagName"].ToString();
                int width = 350;
                int height = 233;
                photoInfo.src = "AJAX/Thumbnail.ashx?pid="+id+"&width="+width+"&height="+height;
                ResponseTemplate(photoInfo);
                IsSuccess = true;
            }
            catch
            {
                IsSuccess = false;
            }
        }
    }
}